

let BaseView = require('../BaseView');

let templateDiv = `
            <label>过关条件</label>
            <div>
                <div>
                    <label>限时</label>
                    <select id="pass_time">
                        <option value="0">不限时</option>
                        <option value="60">60s</option>
                        <option value="90">90s</option>
                        <option value="120">120s</option>
                        <option value="150">150s</option>
                        <option value="180">180s</option>
                    </select>
                </div>
                <div>
                    <label>得分</label>
                    <input class="mini_input" type="number" id="pass_score" value="0">
                </div>
                <div>
                    <label>拯救动物</label>
                    <input class="mini_input" id="pass_animal" type="number" value="0" class="medium">
                </div>
                <!--<div>-->
                    <!--<label>钻石_1</label>-->
                    <!--<input id="diamond_1" type="number" value="0" class="medium">-->
                <!--</div>-->
                <!--<div>-->
                    <!--<label>钻石_2</label>-->
                    <!--<input id="diamond_2" type="number" value="0" class="medium">-->
                <!--</div>-->
                <!--<div>-->
                    <!--<label>钻石_3</label>-->
                    <!--<input id="diamond_3" type="number" value="0" class="medium">-->
                <!--</div>-->
                <!--<div>-->
                    <!--<label>钻石_4</label>-->
                    <!--<input id="diamond_4" type="number" value="0" class="medium">-->
                <!--</div>-->
            </div>
`;

let doubleBind = require('../../doubleBind');

class PassView extends  BaseView{
    constructor() {
        super();

        this.rootEl = document.createElement('div');
        this.rootEl.classList.add('border');
        this.rootEl.innerHTML = templateDiv;

        this.bindModel();
        this.reset();
    }

    bindModel(){

        let lst = [];
        lst.push({
            el:this.rootEl.querySelector('#pass_time'),
            name:'time',
            domName:'select',
            bNumber:true,
        });

        lst.push({
            el:this.rootEl.querySelector('#pass_score'),
            name:'score',
            domName:'input',
            bNumber:true,
        });

        lst.push({
            el:this.rootEl.querySelector('#pass_animal'),
            name:'animal',
            domName:'input',
            bNumber:true,
        });

        this.model = {};
        lst.forEach(item=>{
            doubleBind(this.model,item);
        });
    }

    reset(){
        this.model.time = 0;
        this.model.score = 0;
        this.model.animal = 0;
    }

    // init(model){
    //     this.timeEl.value = model.time;
    //     this.scoreEl.value = model.score;
    //     this.animalEl.value = model.animal;
    // }

    parseCond(condData){
        this.model.time = condData.time;
        this.model.score = condData.score;
        this.model.animal = condData.anim;
        // this.init(this.model);
        // this.diamondEl1.value = condData.d_1;
        // this.diamondEl2.value = condData.d_2;
        // this.diamondEl3.value = condData.d_3;
        // this.diamondEl4.value = condData.d_4;
    }

    getCondModel(){
        // 限时
        // 得分
        // 拯救动物个数
        return {
            time:this.model.time,
            score:this.model.score,
            anim:this.model.animal,
        }
    }
}


module.exports = PassView;
